package cn.stronglink.assetmanage.business.inspection.view.already;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.MainActivity;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.inspection.adapter.PatrolListAdapter;
import cn.stronglink.assetmanage.business.inspection.adapter.PatrolOrderAdapter;
import cn.stronglink.assetmanage.business.inspection.view.IPatrolInView;
import cn.stronglink.assetmanage.business.inspection.view.PatrolDetail.PatrolDetailFragment;
import cn.stronglink.assetmanage.business.inspection.view.repairDetail.RepairDetailFragment;
import cn.stronglink.assetmanage.entity.InventoryDetail;
import cn.stronglink.assetmanage.entity.Patrol;
import cn.stronglink.assetmanage.entity.PatrolDetail;
import cn.stronglink.assetmanage.index.entity.PromissionEntity;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 已巡检界面
 * Created by zhengjinglan on 2018/6/15.
 */

public class AlreadyPatrolView implements IPatrolInView {

    private Fragment fragment;
    //已巡检资产列表布局
    LinearLayout ll_patrol_order_name;
    //表单
    TextView tv_patrol_order_name;
    //操作日期
    TextView tv_patrol_operation_date;
    //已巡检表单列表
    RecyclerView rv_patrol_order_list;
    //每个表单中的资产列表
    ExpandableListView rv_patrol_list;
    //显示资产列表时，扫描操作布局
    LinearLayout ll_patrol;
    //表单列表adapter
    private  PatrolListAdapter listAdapter;
    //资产列表adapter
    private PatrolOrderAdapter orderAdapter;
    public AlreadyPatrolView(Fragment fragment, View view, PatrolListAdapter listAdapter, PatrolOrderAdapter orderAdapter) {
        this.fragment = fragment;
        this.listAdapter = listAdapter;
        this.orderAdapter = orderAdapter;
        initViews(view);
    }


    public Fragment getFragment() {
        return fragment;
    }

    private void initViews(View view) {
        ll_patrol_order_name=view.findViewById(R.id.ll_already_order_name);
        tv_patrol_order_name=view.findViewById(R.id.tv_already_order_name);
        tv_patrol_operation_date=view.findViewById(R.id.tv_already_operation_date);
        rv_patrol_order_list=view.findViewById(R.id.rv_already_order_list);
        rv_patrol_list=view.findViewById(R.id.rv_already_list);
        ll_patrol=view.findViewById(R.id.ll_already);

    }



    /**
     * 显示已巡检资产列表
     */
    @Override
    public void showAssetView() {
        rv_patrol_order_list.setVisibility(View.GONE);
        ll_patrol_order_name.setVisibility(View.VISIBLE);
        rv_patrol_list.setVisibility(View.VISIBLE);
        ll_patrol.setVisibility(View.VISIBLE);
    }

    /**
     *设置已巡检表单数据
     * @param inventoryList
     */
    @Override
    public void setListData(List<Patrol> inventoryList) {
        listAdapter.notifyDatasChanged(inventoryList);
    }



    /**
     * 显示未盘点资源列表表头
     */
    @Override
    public void showAssetTitle(Patrol inventory) {
        tv_patrol_order_name.setText(inventory.getId_());
        tv_patrol_operation_date.setText(inventory.getEndTime());
    }

    public void showOrderDetail(PatrolDetail patrol){
        //跳转到详情页面

        MainActivity activity = (MainActivity) fragment.getActivity();
        PromissionEntity pe = new PromissionEntity();
        pe.setFragment(new PatrolDetailFragment());
        pe.setPosition(MainActivity.FRAGMENT_PATROL_DETAIL_ID);
        pe.setTitle("资产详情");
        // 设置打开盘点详情后传递的参数
        Bundle bundle=new Bundle();
        bundle.putSerializable(Constants.PATROL_DETAIL_NO, patrol.getAssetNo());
        pe.setBundle(bundle);
        activity.onEventRegister(pe);
    }
}
